﻿import QtQuick 2.0
import QtQuick.Controls 2.1
import "../../common"
import "../../../js/util.js" as Util
import "../../../js/UI.js" as Style

Page {
    id: problemFeedback
    property var finishedcallback: null

    ListModel {
        id: updatePic
        ListElement {imageSource: "qrc:/images/add-pic.png"; selectImage: ""}
    }

    ATitle{
        id: m_Title_id
        anchors.top: parent.top
        anchors.left: parent.left
        onBackSignal: {
            subpageSignal(1,-1)
        }
        m_text: qsTr("问题反馈")

        rightItem:BButton{
            anchors.fill: parent
            enabled: text_area.length>0? true :false
            m_text_color: text_area.length>0?Style.titlePontColor:"grey"
            m_text.text: "提交"
            m_text.font.pointSize: 14

            onSigClick:  {
                var filePath=[]
                for(var i=0; i<updatePic.count-1; i++) {
                    filePath.push(updatePic.get(i).selectImage)
                }
                if(filePath.length>0) {
                    var filePaths = filePath.join(";")
                    var data = qsTr("%1,%2,%3").arg(softPhoneManager.phone).arg(text_area.text).arg(filePaths)
                    var param = qsTr("phone,content,file_ss")
                    registhttp.httpRequestImage(softphoneUrlManager.getFeedbackAddress()
                                                , data, param, filePaths)
                }
                var str = "提交成功！"
                var temp = Util.showPopWin(m_root_id,"qrc:/qml/form/dialog/Dialog_sure_and_cancel_warning.qml",str,function(retValue){});
                temp.sure_cancel_signal.disconnect(onSure_cancel_signal)
                temp.sure_cancel_signal.connect(onSure_cancel_signal)
            }
        }
    }

    Rectangle {
        id: m_body
        width: parent.width
        height: m_lineValue * 4
        radius: m_lineValue*0.2
        border.color: "transparent"
        color: "transparent"
        anchors{
            top: m_Title_id.bottom
            topMargin: 0.1*m_lineValue
            left: parent.left
            leftMargin: 0.1*m_lineValue
            right: parent.right
            rightMargin: 0.1*m_lineValue
        }

        Flickable {
            id: flickable
            anchors.fill: parent
            anchors.margins: problemFeedback.height*0.023
            clip: true
            //                    boundsBehavior: Flickable.DragOverBounds
            flickableDirection: Flickable.VerticalFlick

            TextArea.flickable: TextArea {
                id: text_area
                wrapMode: TextArea.Wrap
                font.pointSize: 14
                //                    font.family: fontloader.name
                color: "#323232"
                property int maxLength : 200
                onLengthChanged: {
                    if(text_area.length > maxLength)
                    {
                        var prePosition = cursorPosition;
                        text_area.text = text_area.text.substring(0, maxLength);
                        cursorPosition = Math.min(prePosition, maxLength);
                    }
                }
                AText{
                    width: parent.width
                    wrapMode: TextArea.Wrap
                    visible: text_area.length>0?false:true
                    text: qsTr("请仔细描述您的问题")
                    font.pointSize: 14
                    color: "#b2b2b2"
                }
                //                        placeholderText: qsTr("请仔细描述您的问题，点击下方“+”号提交问题截图，最多三张，帮助我们更快定位您的问题")
            }
            ScrollBar.vertical: ScrollBar { size: 2 }

            onFlickingVerticallyChanged: {
                Qt.inputMethod.hide()
            }
        }

        AText{
            anchors.right: parent.right
            anchors.rightMargin: 0.2 * m_lineValue
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 0.2 * m_lineValue
            text:{
                return qsTr("%1/200").arg(text_area.length)
            }

            color: "#b2b2b2"
            font.pointSize: 14
        }

        SplitLine{
            color: "#e5e5e5"
            anchors.bottom: parent.bottom
            anchors.left: parent.left
            width: parent.width
        }
    }
    function onSure_cancel_signal(value)
    {
        if(value)
            subpageSignal(1,-1);
    }
}
